package com.shujia.redisHotGoods;

import com.shujia.utils.MySQLTool;
import redis.clients.jedis.Jedis;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class RedisHotGoods {
    private static Jedis jedis = new Jedis("192.168.220.100", 12346);
    private static Connection conn = MySQLTool.getMySqlConnection();
    private static Statement state;

    static {
        try {
            state = conn.createStatement();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {


//        putsHuaWei();
        putsLenovo();
    }

    public static void putsHuaWei(){
        try {
            ResultSet resultSet = state.executeQuery("select id from jd_goods where gname like '%华为%'");
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                jedis.sadd("电脑:华为",Integer.valueOf(id).toString());
            }

        }catch ( Exception e){
            e.printStackTrace();
        }
    }

    public static void putsLenovo(){
        try {
            ResultSet resultSet = state.executeQuery("select id from jd_goods where gname like '%联想%'");
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                jedis.sadd("电脑:联想",Integer.valueOf(id).toString());
            }

        }catch ( Exception e){
            e.printStackTrace();
        }
    }
}
